/*******************************************************************************

    Units of Measure for C# applications

    Copyright (C) 2013 Marek Aniola

    This program is provided to you under the terms of the license
    as published at http://unitsofmeasure.codeplex.com/license


********************************************************************************/
using System;

namespace Man.UnitsOfMeasure
{
	public class UnitOfMeasure<T> : Measure<T> where T : struct
	{
		#region Properties

		private string m_separator;
		public string Separator { get { return m_separator; } }

		private string[] m_symbol;
		public int SymbolCount { get { return m_symbol.Length; } }

		#endregion Properties

		#region Constructor(s)

		public UnitOfMeasure(Measure<T> measure, string separator, string[] symbol) :
			base(measure.Scale, measure.Sense, measure.Shift)
		{
			if ((symbol == null) || (symbol.Length < 1) || (Array.FindIndex(symbol, s => String.IsNullOrEmpty(s)) >= 0))
				throw new ArgumentException("Unit symbol array can not be empty/null or contain empty/null elements.");

			m_symbol = symbol;
			m_separator = (separator == null) ? String.Empty : separator;
		}

		#endregion Constructor(s)

		#region Indexer

		public string Symbol(int i)
		{
			return m_symbol[i];
		}

		#endregion Indexer

		#region Formatting

		public override string ToString()
		{
			return ToString(null);
		}

		public override string ToString(IFormatProvider fp)
		{
			return String.Join(", ", m_symbol) + " " + base.ToString(fp);
		}

		#endregion
	}
}
